//
//  YGBaseViewController.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/3/9.
//

#import "YGBaseViewController.h"
#import "MBProgressHUD.h"
@interface YGBaseViewController ()
@property (nonatomic,strong)MBProgressHUD *progressHud;

@end

@implementation YGBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"uitabbaritem_back_icon"] style:UIBarButtonItemStyleDone target:self action:@selector(clickGoBack)];
    UIButton *btn = [[UIButton alloc] init];
    [btn setImage:[UIImage imageNamed:@"uitabbaritem_back_icon"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(clickGoBack) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem = leftItem;
    // Do any additional setup after loading the view.
}

#pragma mark - HUD
- (void)initHud{
    if (self.progressHud) {
        //        [self.progressHud hide:YES];
        [self.progressHud removeFromSuperview];
        self.progressHud = nil;
    }
    self.progressHud = [[MBProgressHUD alloc] initWithView:self.view];
    self.progressHud.delegate = self;
    [self.view addSubview:self.progressHud];
}

- (void)clickGoBack{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)showWithStatus:(NSString*)status{
    [self initHud];
    if (status) {
        self.progressHud.labelText = status;
    }
    [self.progressHud show:YES];
}

- (void)dismissHud{
    [self.progressHud hide:YES afterDelay:0.3];
}

- (void)dismissHudAfterPlay:(CGFloat)time{
    [self.progressHud hide:YES afterDelay:time];
}

- (void)showStatusWithAutoHiden:(NSString*)status{
    [self showWithStatus:status];
    [self dismissHudAfterPlay:1];
}
#pragma mark - MBProgressHUDDelegate

- (void)hudWasHidden:(MBProgressHUD *)hud {
    // Remove HUD from screen when the HUD was hidded
    [hud removeFromSuperview];
    if (hud.mode == MBProgressHUDModeDeterminate) {
        self.progressHud = nil;
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
